#pragma once

#ifndef ___BYTE_BUFFER___
#define ___BYTE_BUFFER___

#include <vector>

using byte = unsigned char;

class ByteBuffer
{
public:
	ByteBuffer() :curRead(0) {}
	ByteBuffer(const char* path);
	bool initWithFile(const char* path);
	size_t read(byte* buf, size_t len);

	byte* data() 
	{
	   return buffer.data();
	}

	const byte* data() const
	{
	   return buffer.data();
	}

	std::vector<byte>& getBuffer() {
		return this->buffer;
	}

	size_t size() const
	{
		return this->buffer.size();
	}

	void resize(const size_t size)
	{
		this->buffer.resize(size);
		if (curRead > size)
		{
			this->curRead = size;
		}
	}
	void clear()
	{
		this->curRead = 0;
		this->buffer.clear();
	}

private:
	size_t curRead;
	std::vector<byte> buffer;
};



#endif // !___BYTE_BUFFER___

